package com.gxa.www.cl.service.impl;

import com.gxa.www.cl.common.base.RespResult;
import com.gxa.www.cl.domain.entity.Sale;
import com.gxa.www.cl.mapper.SaleMapper;
import com.gxa.www.cl.service.SaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SaleServiceImpl implements SaleService {

    @Autowired
    private SaleMapper salesMapper;

    @Override
    public void addSale(Map<String, Object> formData) {
        // 实现添加销售记录的逻辑
        // 这里假设 formData 包含了添加销售记录所需的所有字段
        Sale sale = new Sale();
        // 设置 sale 的属性
        sale.setDanjuhao((String) formData.get("danjuhao"));
        sale.setShijian((String) formData.get("shijian"));
        sale.setZongjiage((Double) formData.get("zongjiage"));
        sale.setJingshouren((String) formData.get("jingshouren"));
        sale.setBeizhu((String) formData.get("beizhu"));
        // 调用 mapper 插入销售记录
        salesMapper.insertSale(sale);
    }

    @Override
    public RespResult deleteSale(Long id) {
        int result = salesMapper.deleteSaleById(id);
        if (result <= 0) {
            throw new RuntimeException("删除失败");
        }
        return null;
    }

    @Override
    public List<Sale> getAllSales() {
        return salesMapper.selectAllSales();
    }
}
